home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
6_10.lha
/
6_10
/
6_10tst3.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
2KB
|
84 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
include <stream.h>
include <string.h>
include <values.h>
include "lint.h"
oid testdiv(LINT A, LINT B)
LINT quot = A / B;
cout << A << " / " << B << " = " << quot << "\n";
oid testmod(LINT A, LINT B)
LINT rem = A % B;
cout << A << " % " << B << " = " << rem << "\n";
oid testdivmod(LINT A, LINT B)
LINT quot, rem;
dodivmod(A, B, quot, rem);
cout << A << " / " << B << " = " << quot << "\n";
cout << A << " % " << B << " = " << rem << "\n";
oid testmul(LINT A, LINT B)
LINT prod = A * B;
cout << A << " * " << B << " = " << prod << "\n";
oid testadd(LINT A, LINT B)
LINT sum = A + B;
cout << A << " + " << B << " = " << sum << "\n";
oid testsub(LINT A, LINT B)
LINT diff = A - B;
cout << A << " - " << B << " = " << diff << "\n";
oid testneg(LINT A)
LINT neg = -A;
cout << " 0, 0 - " << A << " = " << neg << "\n";
oid testpos(LINT A)
LINT pos = +A;
cout << " 0, 0 + " << A << " = " << pos << "\n";
nline int eq(char*s1, char*s2)
return (strcmp(s1, s2) == 0);
ain()
LINT x = 0, y = 0;
char op[100];
while (cin >> x >> op >> y)
{
if (eq(op, "+")) testadd(x, y);
else if (eq(op, "-")) testsub(x, y);
else if (eq(op, "*")) testmul(x, y);
else if (eq(op, "/")) testdiv(x, y);
else if (eq(op, "%")) testmod(x, y);
else if (eq(op, "/%")) testdivmod(x, y);
else if (eq(op, "--")) testneg(x);
else if (eq(op, "++")) testpos(x);
else cout << "unknown operator\n";
}
return 0;